home *** CD-ROM | disk | FTP | other *** search
- Version 1.00
- BEGIN Form Tree
- AutoRedraw = 0
- BackColor = QBColor(7)
- BorderStyle = 2
- Caption = "Tree"
- ControlBox = -1
- Enabled = -1
- ForeColor = QBColor(0)
- Height = Char(19)
- Left = Char(8)
- MaxButton = -1
- MinButton = -1
- MousePointer = 0
- Tag = ""
- Top = Char(2)
- Visible = -1
- Width = Char(64)
- WindowState = 0
- BEGIN ListBox Liste1
- BackColor = QBColor(7)
- DragMode = 0
- Enabled = -1
- ForeColor = QBColor(0)
- Height = Char(13)
- Left = Char(2)
- MousePointer = 0
- Sorted = 0
- TabIndex = 0
- TabStop = -1
- Tag = ""
- Top = Char(1)
- Visible = -1
- Width = Char(58)
- END
- BEGIN CommandButton Befehl1
- BackColor = QBColor(7)
- Cancel = 0
- Caption = "Exit"
- Default = 0
- DragMode = 0
- Enabled = -1
- Height = Char(3)
- Left = Char(2)
- MousePointer = 0
- TabIndex = 1
- TabStop = -1
- Tag = ""
- Top = Char(14)
- Visible = -1
- Width = Char(12)
- END
- END
- DEFINT A-Z
-
- ' This is a simple form to show how I handled the
- ' display of a tree with dynamic expanding and
- ' compressing.
- '
- ' I used it in a program to display structured data
- ' from a Netware SQL database which was too big to
- ' use a control like MicroHelp's MhTree.
- '
- ' This is only a small extract of the code for the
- ' form where some features are added like showing
- ' a plus (+) character in a line that can be
- ' extracted and so on.
- '
- ' If anyone out there uses and enhances my routines
- ' please let me know.
- ' I can be reached at Compuserve ID 100021,2304
- '
- ' Ralf Stoepper
-
- SUB Befehl1_Click ()
- END
- END SUB
-
- SUB Form_Load ()
- tree.liste1.ADDITEM "Root" ' initialize listbox
- tree.SHOW
- tree.liste1.SETFOCUS
- END SUB
-
- SUB Liste1_DblClick ()
- index = liste1.listindex
-
- ' Calculate beginning position of text (begpos)
-
- s$ = liste1.list(index)
- begpos = INSTR(s$, "└")
- IF begpos < 1 THEN
- begpos = INSTR(s$, "├")
- END IF
-
- ' look at folowing item to see if expand or compress
-
- s$ = liste1.list(index + 1)
- pp = INSTR(begpos + 1, s$, "└")
- IF pp < 1 THEN
- pp = INSTR(begpos + 1, s$, "├")
- END IF
- IF pp > 0 THEN
- ' compress
- l = index + 1 ' next index
- DO
- s$ = liste1.list(l)
-
- pp = INSTR(begpos + 1, s$, "└") ' calculate depth
- IF pp < 1 THEN
- pp = INSTR(begpos + 1, s$, "├")
- END IF
-
- IF pp > 0 THEN ' if current item deeper than startitem
- liste1.REMOVEITEM l ' remove it
- END IF
-
- IF liste1.listcount <= l THEN ' if current item = last item then stop
- pp = 0
- END IF
- LOOP UNTIL pp < 1
- ELSE
- ' expand
- IF begpos = 0 THEN ' If first then
- start = 0 ' start at first column
- ELSE ' else
- start = begpos + 3 ' startcolumn is 3 columns deeper
- END IF
-
- vor$ = SPACE$(start) ' build headerstring
-
- s$ = liste1.list(index) ' look at selected string to
- i = 0 ' see where to put in "│"
- DO
- i = INSTR(i + 1, s$, "│") ' if original string contains "│"
- IF i > 0 AND i <= begpos THEN
- MID$(vor$, i, 1) = "│" ' then put "│" in header
- END IF
- LOOP WHILE i > 0
- i = 0
- DO
- i = INSTR(i + 1, s$, "├") ' if original string contains "│"
- IF i > 0 AND i <= begpos THEN
- MID$(vor$, i, 1) = "│" ' then put "│" in header
- END IF
- LOOP WHILE i > 0
-
- l = liste1.listindex + 1 ' Index where to add item
-
- ' getfirst
- aus$ = " 1" 'this should be replaced by a routine
- 'to calculate the first sub-item
- 'The routine should return a zero string ("")
- 'when no sub-item is found
-
-
- WHILE aus$ <> ""
- pfeil$ = "├──"
- liste1.ADDITEM vor$ + pfeil$ + aus$, l
-
- ' get next 'this should be replaced by a routine
- IF VAL(aus$) = 3 THEN 'to calculate the next sub-item
- aus$ = "" 'The routine should return a zero string ("")
- ELSE 'when no sub-item is found
- aus$ = STR$(VAL(aus$) + 1)
- END IF
-
- l = l + 1 ' next index to add item
- IF aus$ = "" THEN ' if no next item can be found then
- s$ = liste1.list(l - 1) ' place a "└".
- MID$(s$, start + 1, 1) = "└"
- liste1.list(l - 1) = s$
- END IF
- WEND
- END IF
- END SUB
-
-